Skip to content

Add support for alternatiwe image formats like webp and avif - #1651

Open
tito10047 wants to merge 23 commits into
liip:2.xfrom
tito10047:avif
Open

Add support for alternatiwe image formats like webp and avif#1651
tito10047 wants to merge 23 commits into
liip:2.xfrom
tito10047:avif

Conversation

@tito10047

@tito10047 tito10047 commented Feb 19, 2026

Copy link
Copy Markdown
Contributor

…update handling of modern image formats (WebP, AVIF).

Q A
Branch? 2.x
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? yes
Fixed tickets #1314
License MIT
Doc yes

Description

This PR refactors the way modern image formats (like WebP and AVIF) are handled within the bundle. Instead of having hardcoded logic for a single format, it introduces a generic Alternative Formats system.

Key changes:

  • Unified Configuration: Introduced alternative_formats configuration tree.
  • BC Compatibility: Existing webp configuration is automatically normalized into the new structure using a beforeNormalization step in Configuration.php.
  • Format Negotiation: Added a FormatNegotiator service to dynamically select the best image format based on the browser's Accept header (supporting AVIF, WebP, etc.).
  • Abstrakcia: Refactored FilterPathContainer to support any alternative format, while marking createWebp() as deprecated.
  • Extensibility: New formats like AVIF can now be enabled simply by adding them to the configuration without changing the bundle's core logic.

This approach follows the discussion in issue #1314, providing a future-proof solution for modern image delivery while ensuring zero breaking changes for existing installations.

Proff of concept here: just6words.com

@coveralls

coveralls commented Feb 19, 2026

Copy link
Copy Markdown

Coverage Status

coverage: 81.235% (+1.1%) from 80.126% — tito10047:avif into liip:2.x

@tito10047

Copy link
Copy Markdown
Contributor Author

Hi @dbu . can you help me with cs fixer? I run cs fixer as you mentioned me last time, but nothing is fixed in me setup
docker run --rm -v /home/jozefm/phpProjects/contrib/LiipImagineBundle:/code ghcr.io/php-cs-fixer/php-cs-fixer:3.66-php8.0 fix

Thx

@tito10047 tito10047 changed the title Deprecate webp configuration in favor of alternative_formats and … Add support for alternatiwe image formats like webp and avif Feb 19, 2026
…agic driver can convert to avif, imagick convert to avif before postProcessor. so I add this option use_default_driver. only if this option is set to true (defaut) imagick will convert to avif. otherwise will be do it avifenc binary
@tito10047
tito10047 marked this pull request as ready for review February 19, 2026 22:33
@tito10047

Copy link
Copy Markdown
Contributor Author

Hi @dbu . Will you look at this PR please?

@dbu

dbu commented Mar 18, 2026

Copy link
Copy Markdown
Collaborator

thanks for looking into this. the current approach is certainly not ideal. your refactoring makes it more flexible. but we saw that the basic idea of serving a webp under the jpg url is problematic (http caching, need to call the controller each time)

i wonder why we don't use the element for this:

<picture>
  <source srcset="photo.avif" type="image/avif" />
  <source srcset="photo.webp" type="image/webp" />
  <img src="photo.jpg" alt="photo" />
</picture>

then its up to the browser to chose the best option, and urls are clean again, allowing for proper caching and avoiding any hacks and capability sniffing in the backend.

this can be built with the imagine_filter , we could additionally provide a tool for the <source srcset entries (or the whole picture element, but that would be a bit tricky because one might need all kinds of attributes in the <img> tag.

@tito10047

Copy link
Copy Markdown
Contributor Author

Ok, But this PR is the same aproach as is already in this bundle. so nothing is changed. only some refactoring.
And we can build uppn this pr helper your suggested, helsper without controller calling

@dbu dbu left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i took a closer look now. the refactoring is well done and a much better and future proof way to achieve what the webp flag does. i am still unhappy that it deepens a pattern that i think we should move away from. in that way it sends a wrong signal to users who upgrade.

at the same time I don't have much time to work on the bundle, so it might be quite a while until i can address that. therefore lets merge this.

i commented on some details. can you please also add a changelog entry to explain the deprecation and the more generic solution, but also point out that client side resolving is the preferred way for supporting webp, avif etc?

$webpGenerate = false
$alternativeFormats = false
) {
if (\is_bool($alternativeFormats)) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could we default the parameter to [] instead? otherwise not setting alternative formats triggers a deprecation

$this->dispatcher = $dispatcher;
$this->defaultResolver = $defaultResolver ?: 'default';
$this->webpGenerate = $webpGenerate;
$this->alternativeFormats = $alternativeFormats;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i would normalize this to have the property only accept array and translate false to [] and true to ['webp]. that way the BC is constrained to the constructor and the rest of the class simpler.

Comment thread Service/FilterService.php
* @param string $path
* @param string $filter
* @param string|null $resolver
* @param bool $webpSupported

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @param bool $webpSupported
* @param bool $webpSupported deprecated in favor of $alternativeFormatsSupported

Comment thread Service/FilterService.php
* @param string $path
* @param string $filter
* @param string|null $resolver
* @param bool $webpSupported

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @param bool $webpSupported
* @param bool $webpSupported deprecated in favor of $alternativeFormatsSupported

- name: Run PHPUnit tests
env:
SYMFONY_DEPRECATIONS_HELPER: max[self]=0
SYMFONY_DEPRECATIONS_HELPER: disabled=1

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please don't change this setting.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was not addressed

service('liip_imagine.filter.manager'),
service('liip_imagine.cache.manager'),
'%liip_imagine.webp.generate%',
'%liip_imagine.webp.options%',

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there no risk of BC break? does the extension integrate the parameters into alternative_formats if the old parameters are set?

Comment thread Resources/doc/basic-usage.rst
Comment thread Resources/doc/basic-usage.rst
@tito10047

Copy link
Copy Markdown
Contributor Author

Hi, i can preprare new PR, with idea you want. So lets freeze this PR and I will do on new one. Ok? You want say me something what os your idea closer?

But... When i will do new PR and abamdonenthis idea, there will must be BC. So what is better, accpet this with non BC or release new version with BC. I like second option.

@dbu

dbu commented Mar 23, 2026

Copy link
Copy Markdown
Collaborator

if you can address my comments here, we can merge this pull request, then at least there is a better support for the server-side negotiation. i think there is not much work left to do, and then we have an improvement we can release.

@tito10047

Copy link
Copy Markdown
Contributor Author

Sorry for the delay, I had plent of new projects to do :)

@@ -1,84 +1,63 @@
parameters:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please revert these whitespace changes, the whitespace is for readability

Comment thread .gitignore
/var/
/vendor/
/.idea/
/.junie/guidelines.md

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please do not add local dev environment specific things to the gitignore. use your global gitignore on your workstation for those.

@dbu

dbu commented Jun 10, 2026

Copy link
Copy Markdown
Collaborator

you closed some of my comments without response. i reopened those. please adress them so that we have a smooth upgrade path.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants